﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Xml.Linq;
using OSVDB_Model;
using System.Collections.ObjectModel;
using System.ComponentModel;

namespace OSVDB_Logic
{
    public class PacketStormADV_BL : IVulns
    {
        private String url;

        public PacketStormADV_BL(String url)
        {
            this.url = url;
        }

        #region IVulns Members

        public Collection<OSVDB_Model.AbstractVuln> getAll()
        {
            try
            {
                Collection<AbstractVuln> list = new Collection<AbstractVuln>();
                WebClient wc = new WebClient();
                string xml = wc.DownloadString(this.url);

                XDocument doc = XDocument.Parse(xml);

                var items = from item in doc.Descendants("item")
                            orderby item.Element("title").Value descending
                            select item;

                foreach (XElement element in items)
                {
                    list.Add(new PacketStormADV(element.Element("title").Value.ToString(), element.Element("link").Value.ToString(), element.Element("description").Value.ToString()));
                }

                return list;
            }
            catch (Exception e)
            {
                
                throw;
            }
            
        }

        private DateTime getFormattedDate(string p)
        {
           DateTime date = DateTime.Parse(p);
           return date;
        }

        public OSVDB_Model.AbstractVuln getSpecific()
        {
            throw new NotImplementedException();
        }

        #endregion

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion
    }
}
